<template>
  <div class="app-container">
    <el-container>
      <el-main>
        <el-row :gutter="10">
          <el-col :span="4">
            <div>
              <el-select v-model="query_type" placeholder="查询类型">
                <el-option
                  v-for="item in options1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div>
              <el-select v-model="query_scope" placeholder="目标类型">
                <el-option
                  v-for="item in options2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="4">
            <div>
              <el-select v-model="target_type" placeholder="查询范围">
                <el-option
                  v-for="item in options3"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="6">
            <div>
              <span class="demonstration"></span>
              <el-date-picker
                v-model="start_date"
                type="date"
                placeholder="请选择开始日期">
              </el-date-picker>
            </div>
          </el-col>
          <el-col :span="6">
            <div>
              <el-time-picker
                v-model="start_time"
                :picker-options="{
      selectableRange: '00:00:00 - 23:59:59'
    }"
                placeholder="请选择开始时间">
              </el-time-picker>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <div>
              <el-input
                placeholder="请输入产品编号"
                v-model="product_number"
                clearable>
              </el-input>
            </div>
          </el-col>
          <el-col :span="6">
            <div>
              <span class="demonstration"></span>
              <el-date-picker
                v-model="end_date"
                type="date"
                placeholder="请选择结束日期">
              </el-date-picker>
            </div>
          </el-col>
          <el-col :span="6">
            <div>
              <el-time-picker
                v-model="end_time"
                :picker-options="{
      selectableRange: '00:00:00 - 23:59:59'
    }"
                placeholder="请选择结束时间">
              </el-time-picker>
            </div>
          </el-col>
          <el-col :span="4">
            <el-button @click="inquire" style="width: 130px" type="info" plain>查询</el-button>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
    <el-table
      ref="filterTable"
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="date"
        label="日期"
        sortable
        width="180"
        column-key="date"
        :filters="[{text: '2016-05-01', value: '2016-05-01'}, {text: '2016-05-02', value: '2016-05-02'}, {text: '2016-05-03', value: '2016-05-03'}, {text: '2016-05-04', value: '2016-05-04'}]"
        :filter-method="filterHandler"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        :formatter="formatter">
      </el-table-column>
      <el-table-column
        prop="tag"
        label="标签"
        width="100"
        :filters="[{ text: '家', value: '家' }, { text: '公司', value: '公司' }]"
        :filter-method="filterTag"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.tag === '家' ? 'primary' : 'success'"
            disable-transitions>{{scope.row.tag}}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style lang="scss">
  .el-row {
    margin-bottom: 20px;

  &
  :last-child {
    margin-bottom: 0;
  }
  }
</style>
<script>
import 'driver.js/dist/driver.min.css'
import { getInfo } from '@/api/history' // import driver.js css
export default {
  name: 'Guide',
  data() {
    return {
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄',
        tag: '家'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄',
        tag: '公司'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄',
        tag: '家'
      }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          tag: '公司'
      }],
      options1: [{
          value: '选项1',
          label: 'A'
      }, {
          value: '选项2',
          label: 'B'
      }, {
          value: '选项3',
          label: 'C'
      }, {
          value: '选项4',
          label: 'D'
      }, {
          value: '选项5',
          label: 'E'
      }], options2: [{
          value: '选项1',
          label: '①'
      }, {
          value: '选项2',
          label: '②'
      }, {
          value: '选项3',
          label: '③'
      }, {
          value: '选项4',
          label: '④'
      }, {
          value: '选项5',
          label: '⑤'
      }], options3: [{
          value: '选项1',
          label: '1'
      }, {
          value: '选项2',
          label: '2'
      }, {
          value: '选项3',
          label: '3'
      }, {
          value: '选项4',
          label: '4'
      }, {
          value: '选项5',
          label: '5'
      }],
      query_type: '',
      query_scope: '',
      target_type: '',
      start_date: '',
      start_time: '',
      end_date: '',
      end_time: '',
      product_number: ''
    }
  },
  methods: {
    resetDateFilter() {
        this.$refs.filterTable.clearFilter('date')
    },
    clearFilter() {
        this.$refs.filterTable.clearFilter()
    },
    formatter(row, column) {
        return row.address
    },
    filterTag(value, row) {
        return row.tag === value
    },
    filterHandler(value, row, column) {
        const property = column['property']
        return row[property] === value
    },
    inquire() {
      getInfo(this.query_type, this.query_scope, this.target_type,
        this.start_date, this.start_time, this.end_date,
        this.end_time, this.product_number).then(response => {
        alert('yes')
        // this.deviceList = response.data
      })
    }
  }
}
</script>
